{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Can Make Arithmetic Progression From Sequence"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #sorting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #排序"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: canMakeArithmeticProgression"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #判断能否形成等差数列"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个数字数组 <code>arr</code> 。</p>\n",
    "\n",
    "<p>如果一个数列中，任意相邻两项的差总等于同一个常数，那么这个数列就称为 <strong>等差数列</strong> 。</p>\n",
    "\n",
    "<p>如果可以重新排列数组形成等差数列，请返回 <code>true</code> ；否则，返回 <code>false</code> 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>arr = [3,5,1]\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>对数组重新排序得到 [1,3,5] 或者 [5,3,1] ，任意相邻两项的差分别为 2 或 -2 ，可以形成等差数列。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>arr = [1,2,4]\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>无法通过重新排序得到等差数列。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>2 &lt;= arr.length &lt;= 1000</code></li>\n",
    "\t<li><code>-10^6 &lt;= arr[i] &lt;= 10^6</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [can-make-arithmetic-progression-from-sequence](https://leetcode.cn/problems/can-make-arithmetic-progression-from-sequence/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [can-make-arithmetic-progression-from-sequence](https://leetcode.cn/problems/can-make-arithmetic-progression-from-sequence/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[3,5,1]', '[1,2,4]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr=sorted(arr)\n",
    "        temp=arr[1]-arr[0]\n",
    "        for i in range(0,len(arr)-1):\n",
    "            if (arr[i+1]-arr[i])!=temp:\n",
    "                return False\n",
    "        return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        #if len(arr) == 2: return True\n",
    "        # arr = sorted(arr)\n",
    "        # for i in range(1, len(arr)-1):\n",
    "        #     if arr[i+1] - arr[i] != arr[i] - arr[i-1]:\n",
    "        #         return False\n",
    "        # return True \n",
    "        arr.sort()\n",
    "        tmp = [arr[i+1]-arr[i] for i in range(len(arr)-1)]\n",
    "        if len(set(tmp)) == 1:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        for i in range(1, len(arr) - 1):\n",
    "            if arr[i + 1] - arr[i] != arr[i] - arr[i - 1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        n =len(arr)\n",
    "        arr=sorted(arr)\n",
    "        d = arr[0]-arr[1]\n",
    "        for i in range(n-1):\n",
    "            if arr[i]-arr[i+1]!=d:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        d = arr[1] - arr[0]\n",
    "        for i in range(2, len(arr)):\n",
    "            if arr[i] - arr[i-1] != d:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        a=[arr[i+1]-arr[i] for i in range(len(arr)-1)]\n",
    "        return len(set(a)) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort(reverse=False)\n",
    "        if(len(arr)==2):\n",
    "            return True\n",
    "        else:\n",
    "            arrDiff=arr[1]-arr[0]\n",
    "            for i in range(len(arr)-1):\n",
    "                if (arr[i+1]-arr[i]!=arrDiff):\n",
    "                    return False\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        for i in range(1, len(arr) - 1):\n",
    "            if arr[i] * 2 != arr[i - 1] + arr[i + 1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        x = len(arr)\n",
    "        cha = arr[1] - arr[0]\n",
    "        res = True\n",
    "        for i in range(1, x-1):\n",
    "            if arr[i+1] - arr[i] == cha:\n",
    "                res = True\n",
    "            else:\n",
    "                res = False\n",
    "                break\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        n=len(arr)\n",
    "        p=arr[1]-arr[0]\n",
    "        for i in range(1,n):\n",
    "            if arr[i]-arr[i-1]!=p:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        if len(arr) == 2:\n",
    "            return True\n",
    "        arr.sort()\n",
    "        base = arr[1] - arr[0]\n",
    "        for i in range(2, len(arr)):\n",
    "            if arr[i]- arr[i-1]!=base:\n",
    "                return False\n",
    "        return True\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr=sorted(arr)\n",
    "        for i in range(0,len(arr)-2):\n",
    "            if (arr[i+2]-arr[i+1])!=(arr[i+1]-arr[i]) :\n",
    "               return False\n",
    "    \n",
    "        return True\n",
    "               "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        if arr[1]-arr[0]==0:\n",
    "            if len(set(arr))==1:\n",
    "                return True\n",
    "            else:\n",
    "                return False\n",
    "        if arr==list(range(arr[0],arr[-1]+1,arr[1]-arr[0])):\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        for i in range(len(arr) - 2):\n",
    "            if arr[i] - arr[i + 1] != arr[i + 1] - arr[i + 2]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        for i in range(len(arr)-2):\n",
    "            if arr[i+1]-arr[i]!=arr[i+2]-arr[i+1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        if len(arr) < 3:\n",
    "            return True\n",
    "        arr.sort()\n",
    "        gap = arr[1] - arr[0]\n",
    "        for i in range(1, len(arr) - 1):\n",
    "            if arr[i + 1] - arr[i] != gap:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        a=[arr[i+1]-arr[i] for i in range(len(arr)-1)]\n",
    "        if len(set(a))==1:\n",
    "            return True\n",
    "        else:return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        sorted_arr = sorted(arr)\n",
    "        delet = sorted_arr[1]-sorted_arr[0]\n",
    "        for i in range(len(sorted_arr)-1):\n",
    "            if sorted_arr[i+1] - sorted_arr[i] != delet:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr_len = len(arr)\n",
    "        arr.sort()\n",
    "        if arr_len <= 2:\n",
    "            return True\n",
    "        else:\n",
    "            a = arr[1] - arr[0]\n",
    "            for i in range(arr_len-1):\n",
    "                if arr[i+1]-arr[i] != a:\n",
    "                    return False\n",
    "            return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        diff = arr[0]-arr[1]\n",
    "        for i in range(0,len(arr)-1):\n",
    "            if (arr[i]-arr[i+1] != diff):\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        #if len(arr) == 2: return True\n",
    "        # arr = sorted(arr)\n",
    "        # for i in range(1, len(arr)-1):\n",
    "        #     if arr[i+1] - arr[i] != arr[i] - arr[i-1]:\n",
    "        #         return False\n",
    "        # return True \n",
    "        arr.sort()\n",
    "        tmp = [arr[i+1]-arr[i] for i in range(len(arr)-1)]\n",
    "        if len(set(tmp)) == 1:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self,list1:list[int]):\n",
    "        list1.sort()\n",
    "        d=list1[1]-list1[0]\n",
    "        n = len(list1)\n",
    "    #遍历\n",
    "        for i in range(2, n):\n",
    "            if list1[i] == list1[i -1] +d:\n",
    "                continue\n",
    "            else:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        for i in range(1, len(arr) - 1):\n",
    "            if arr[i] * 2 != arr[i - 1] + arr[i + 1]:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        d = arr[1] - arr[0]\n",
    "        for i in range(2,len(arr)):\n",
    "            b = arr[i-1]\n",
    "            a = arr[i]\n",
    "            c = a-b\n",
    "            if c == d:\n",
    "                continue\n",
    "            else:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        if len(arr) == 2:\n",
    "            return True\n",
    "        arr.sort()\n",
    "        return all(arr[i]-arr[i-1] == arr[i+1] - arr[i] for i in range(1,len(arr)-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        diff = arr[1]-arr[0]\n",
    "        for i in range(len(arr)-1):\n",
    "            if arr[i+1]-arr[i]!=diff:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        n = arr[1] - arr[0]\n",
    "        for i in range(1,len(arr)):\n",
    "            if arr[i] - arr[i-1] != n:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        if len(arr)==2:\n",
    "            return True\n",
    "        arr1=sorted(arr,reverse=False)\n",
    "        c=arr1[1]-arr1[0]\n",
    "        for i in range(1,len(arr1)-1):\n",
    "            if arr1[i+1]-arr1[i]!=c:\n",
    "                return False\n",
    "        else:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        d = arr[1] - arr[0]\n",
    "        for i in range(1, len(arr)):\n",
    "            if arr[i] != arr[0] + i * d:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        n=len(arr)\n",
    "        p=arr[1]-arr[0]\n",
    "        for i in range(1,n):\n",
    "            if arr[i]-arr[i-1]!=p:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        if len(arr) <= 2:\n",
    "            return True\n",
    "        else:\n",
    "            for index, element in enumerate(arr):\n",
    "                if index-1 >=0 and index+1 < len(arr):\n",
    "                    # print(index)\n",
    "                    # print(arr)\n",
    "                    # print(arr[index])\n",
    "                    # print(arr[index+1])\n",
    "                    # print(arr[index-1])\n",
    "                    # print(arr[index+1] - arr[index])\n",
    "                    # print(arr[index] - arr[index-1])\n",
    "                    if arr[index+1] - arr[index] != arr[index] - arr[index-1]:\n",
    "                        return False\n",
    "                else:\n",
    "                    continue\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        if len(arr)==0 or len(arr)==1:\n",
    "            return False\n",
    "        arr.sort()\n",
    "        dif=arr[1]-arr[0]\n",
    "        for i in range(1,len(arr)):\n",
    "            if arr[i]-arr[i-1] != dif:\n",
    "                return False\n",
    "        \n",
    "        return True\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        for i in range(1, len(arr) - 1):\n",
    "            if arr[i] * 2 != arr[i - 1] + arr[i + 1]:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        x = len(arr)\n",
    "        cha = arr[1] - arr[0]\n",
    "        res = True\n",
    "        for i in range(1, x-1):\n",
    "            if arr[i+1] - arr[i] == cha:\n",
    "                res = True\n",
    "            else:\n",
    "                res = False\n",
    "                break\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        for i in range(len(arr)-2):\n",
    "            if arr[i+1]-arr[i]!= arr[i+2]-arr[i+1]:\n",
    "                return False\n",
    "        else:\n",
    "            return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        m = max(arr)\n",
    "        n = min(arr)\n",
    "        d = (m - n) // (len(arr) - 1)\n",
    "        for i in range(len(arr)):\n",
    "            if n + i * d not in arr or (arr.count(n + i * d) != 1 and arr.count(n + i * d) != len(arr)):\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        if len(arr) == 2: return True\n",
    "        arr = sorted(arr)\n",
    "        for i in range(1, len(arr)-1):\n",
    "            if arr[i+1] - arr[i] != arr[i] - arr[i-1]:\n",
    "                return False\n",
    "        return True \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        return len(set(arr[i] - arr[i-1] for i in range(1,len(arr)))) == 1\n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        a = len(arr)\n",
    "        if a == 2:\n",
    "            return True\n",
    "        i, k = 2, arr[1] - arr[0]\n",
    "        while i < a:\n",
    "            if arr[i] - arr[i-1] != k:\n",
    "                return False\n",
    "            i += 1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self,list1:list[int]):\n",
    "        list1.sort()\n",
    "        d=list1[1]-list1[0]\n",
    "        n = len(list1)\n",
    "    #遍历\n",
    "        for i in range(2, n):\n",
    "            if list1[i] == list1[i -1] +d:\n",
    "                continue\n",
    "            else:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        if len(arr) <= 2:\n",
    "            return True\n",
    "\n",
    "        def partition(arr, left, right):\n",
    "            pivot = arr[left]\n",
    "            while left < right:\n",
    "                while left < right and arr[right] >= pivot:\n",
    "                    right -= 1\n",
    "                arr[left] = arr[right]\n",
    "                while left < right and arr[left] <= pivot:\n",
    "                    left += 1\n",
    "                arr[right] = arr[left]\n",
    "            arr[left] = pivot\n",
    "            return left\n",
    "\n",
    "        def quick_sort(arr, left, right):\n",
    "            if left < right:\n",
    "                pivot_index = partition(arr, left, right)\n",
    "                quick_sort(arr, left, pivot_index - 1)\n",
    "                quick_sort(arr, pivot_index + 1, right)\n",
    "\n",
    "        quick_sort(arr, 0, len(arr) - 1)\n",
    "\n",
    "        for i in range(1, len(arr) - 1):\n",
    "            if arr[i] - arr[i - 1] != arr[i + 1] - arr[i]:\n",
    "                return False\n",
    "\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        # 先排序 内置排序函数\n",
    "        arr.sort()\n",
    "\n",
    "        # 再判断\n",
    "        a = arr[1] - arr[0]\n",
    "        flag = 1\n",
    "        for i in range(2,len(arr)):\n",
    "            if arr[i]-arr[i-1] == a or arr[i]-arr[i-1] == -a:\n",
    "                flag = 1\n",
    "            else:\n",
    "                return False\n",
    "        if flag == 1:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        sub = arr[1]-arr[0]\n",
    "        for i in range(2,len(arr)):\n",
    "            if sub != arr[i]-arr[(i-1)]:\n",
    "                return False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        if len(set(arr[i] - arr[i-1] for i in range(1,len(arr)))) == 1:\n",
    "            return True\n",
    "        return False\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()        \n",
    "        return len(set(arr[i] - arr[i+1]  for i in range(len(arr)-1)))==1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort(reverse = True)\n",
    "        d = arr[0]-arr[1]\n",
    "        for i in range(len(arr)-1):\n",
    "            if arr[i] - arr[i+1] == d:\n",
    "                continue\n",
    "            else:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        a=arr[1]-arr[0]\n",
    "        for i in range(1,len(arr)-1):\n",
    "            if arr[i+1]-arr[i]!=a:\n",
    "                return False\n",
    "        return True\n",
    "        \n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        sorted_arr = sorted(arr,reverse=True)\n",
    "        d = sorted_arr[1] - sorted_arr[0]\n",
    "        for i in range(2,len(sorted_arr)):\n",
    "            if sorted_arr[i] - sorted_arr[i-1] == d:\n",
    "                continue\n",
    "            else:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr1=sorted(arr,reverse=False)\n",
    "        c=arr1[1]-arr1[0]\n",
    "        for i in range(1,len(arr1)-1):\n",
    "            if arr1[i+1]-arr1[i]!=c:\n",
    "                return False\n",
    "        else:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        n = len(arr)\n",
    "        a = [arr[i] - arr[i-1] for i in range(1, n)]\n",
    "        if len(set(a)) == 1:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        x=[arr[i+1]-arr[i] for i in range(len(arr)-1)]\n",
    "        if len(set(x))==1:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr = sorted(arr)\n",
    "        for i in range(len(arr)-2):\n",
    "            if 2*arr[i+1] != arr[i] + arr[i+2]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        # diff = arr[0]-arr[1]\n",
    "        for i in range(0,len(arr)-1):\n",
    "            if (arr[i]-arr[i+1] != arr[0]-arr[1]):\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        a = arr[0]\n",
    "        d = arr[1]-a\n",
    "        for i in range(2,len(arr)):\n",
    "            if d*i!=arr[i]-a:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        #if len(arr) == 2: return True\n",
    "        # arr = sorted(arr)\n",
    "        # for i in range(1, len(arr)-1):\n",
    "        #     if arr[i+1] - arr[i] != arr[i] - arr[i-1]:\n",
    "        #         return False\n",
    "        # return True \n",
    "        arr.sort()\n",
    "        tmp = [arr[i+1]-arr[i] for i in range(len(arr)-1)]\n",
    "        if len(set(tmp)) == 1:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr = sorted(arr)\n",
    "        differ = arr[1]-arr[0]\n",
    "        for i in range(1,len(arr)-1):\n",
    "            if arr[i+1]-arr[i] != differ:\n",
    "                return False\n",
    "                break\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        for i in range(1,len(arr)-1):\n",
    "            if arr[i]*2!=arr[i+1]+arr[i-1]:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        lenght = len(arr)\n",
    "        arr.sort()\n",
    "        print(arr)\n",
    "        x = lenght % 3\n",
    "        l = 1\n",
    "        i = 1\n",
    "        n = 0\n",
    "        while l:\n",
    "            if l+1<lenght:\n",
    "                if arr[l]-arr[l-i] == arr[l+i] -arr[l]:\n",
    "                    l+=1\n",
    "                    continue\n",
    "                print('1')\n",
    "                return False\n",
    "            else:break\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr = sorted(arr)\n",
    "        step = arr[1] - arr[0]\n",
    "        nums = len(arr)\n",
    "        for i in range(nums-1):\n",
    "            if arr[i] - arr[i+1] !=step*(-1):\n",
    "                return False\n",
    "                break\n",
    "            if arr[i+1] == arr[-1]:\n",
    "                return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        d = arr[0] - arr[1]\n",
    "        for i in range(2,len(arr)):\n",
    "            if arr[i-1] - arr[i] != d:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        a=[arr[i+1]-arr[i] for i in range(len(arr)-1)]\n",
    "        if len(set(a))==1:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        d=[]\n",
    "        for i in range(len(arr)):\n",
    "            if i+1<len(arr):\n",
    "                c=arr[i]-arr[i+1]\n",
    "                d.append(c)\n",
    "        if len(set(d))==1:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        d = arr[1]-arr[0]\n",
    "        for i in range(2,len(arr)):\n",
    "            if d*i!=arr[i]-arr[0]:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        for i in range(1,len(arr)-1):\n",
    "            if arr[i]*2!=arr[i-1]+arr[i+1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        ans=arr.sort()\n",
    "        n=len(arr)\n",
    "        for i in range(1,n-1):\n",
    "            if arr[i-1]+arr[i+1]!=2*arr[i]:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: list[int]) -> bool:\n",
    "        arr.sort()\n",
    "        ans = arr[1] - arr[0]\n",
    "        for i in range(1,len(arr)):\n",
    "            if arr[i] - arr[i-1] != ans:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        n = len(arr)\n",
    "        if n < 2:\n",
    "            return False\n",
    "        # 先排序\n",
    "        for i in range(n):\n",
    "            for j in range(i + 1, n):\n",
    "                if arr[i] > arr[j]:\n",
    "                    arr[i], arr[j] = arr[j], arr[i]\n",
    "\n",
    "        diff = arr[1] - arr[0]\n",
    "        for i in range(2, n):\n",
    "            if abs(arr[i] - arr[i - 1]) != abs(diff):\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        # 先排序 冒泡排序\n",
    "        for i in range(len(arr)):\n",
    "            for j in range(len(arr)-1,i,-1):  # 倒序\n",
    "                if arr[j] < arr[j-1]:\n",
    "                    a = arr[j]\n",
    "                    arr[j] = arr[j-1]\n",
    "                    arr[j-1] = a\n",
    "\n",
    "        # 再判断\n",
    "        a = arr[1] - arr[0]\n",
    "        flag = 1\n",
    "        for i in range(2,len(arr)):\n",
    "            if arr[i]-arr[i-1] == a or arr[i]-arr[i-1] == -a:\n",
    "                flag = 1\n",
    "            else:\n",
    "                return False\n",
    "        if flag == 1:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        maxVal, minVal = -1000000, 1000000\n",
    "        n = 0\n",
    "        for x in arr:\n",
    "            n += 1\n",
    "            if x > maxVal:\n",
    "                maxVal = x\n",
    "            if x < minVal:\n",
    "                minVal = x\n",
    "\n",
    "        if (maxVal - minVal) % (n - 1) != 0:\n",
    "            return False\n",
    "        diff = (maxVal - minVal) // (n - 1)\n",
    "        if diff == 0:\n",
    "            return True\n",
    "        \n",
    "        hasOccured = [0] * n\n",
    "        for y in arr:\n",
    "            if (y - minVal) % diff != 0:\n",
    "                return False\n",
    "            pos = (y - minVal) // diff\n",
    "            if hasOccured[pos] == 1:\n",
    "                return False\n",
    "            hasOccured[pos] = 1\n",
    "        \n",
    "        return True\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr = sorted(arr)\n",
    "        prev = arr[1] - arr[0]\n",
    "        i = 1\n",
    "        while i + 1 < len(arr):\n",
    "            if arr[i + 1] - arr[i] != prev:\n",
    "                return False\n",
    "            i += 1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        n = len(arr)\n",
    "        res = [0] * (n - 1)\n",
    "        for i in range(n - 1):\n",
    "            res[i] = arr[i+1] - arr[i] \n",
    "            if i > 0 and res[i] != res[i-1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        for i in range(1,len(arr)-1):\n",
    "            if arr[i] - arr[i-1] == arr[i+1] - arr[i]:\n",
    "                continue\n",
    "            else :\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        dis=arr[1]-arr[0]\n",
    "        for i in range(2,len(arr)):\n",
    "            if (arr[i]-arr[i-1])!=dis:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr.sort()\n",
    "        res=arr[0]-arr[1]\n",
    "        for i in range(len(arr)-1):\n",
    "            if arr[i]-arr[i+1]!=res:\n",
    "                return False\n",
    "        return True\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        arr=sorted(arr)\n",
    "        return len(set(arr[i] - arr[i + 1] for i in range(len(arr) - 1))) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def canMakeArithmeticProgression(self, arr: List[int]) -> bool:\n",
    "        minv = min(arr)\n",
    "        maxv = max(arr)\n",
    "        n = len(arr)\n",
    "        if n == 2:\n",
    "            return True\n",
    "        if (maxv-minv)%(n-1) != 0:\n",
    "            return False\n",
    "        d = (maxv-minv)//(n-1)\n",
    "        if d == 0:\n",
    "            return len(set(arr)) == 1\n",
    "        if n != len(set(arr)):\n",
    "            return False\n",
    "        for i in range(n):\n",
    "            num = minv+d*i\n",
    "            if num not in arr:\n",
    "                return False\n",
    "        return True"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
